package com.ssy.lingxi.order.model.dto;

import com.ssy.lingxi.order.model.constant.BuyerInnerStatusEnum;
import com.ssy.lingxi.order.model.constant.OrderOuterStatusEnum;
import com.ssy.lingxi.order.model.constant.VendorInnerStatusEnum;
import com.ssy.lingxi.order.utils.NumberUtil;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * App - 分页查询订单列表DTO
 * @author 万宁
 * @version 2.0.0
 * @date 2021-09-22
 */
public class MobileOrderQueryDTO implements Serializable {
    private static final long serialVersionUID = 8066039402923217168L;

    public MobileOrderQueryDTO(Long shopId, Long orderId, String orderNo, Integer orderMode, Integer orderKind, Long vendorMemberId, Long vendorRoleId, String vendorMemberName, String vendorLogo, BigDecimal totalAmount, Integer innerStatus, Integer outerStatus, Boolean buyerCommented, Boolean hasPaid, Boolean hasDelivered, Long contractId, Integer promotionStatus, Long groupId, Boolean canRefund, Boolean hasRefund) {
        this.shopId = shopId;
        this.orderId = orderId;
        this.orderNo = orderNo;
        this.orderMode = orderMode;
        this.orderKind = orderKind;
        this.vendorMemberId = vendorMemberId;
        this.vendorRoleId = vendorRoleId;
        this.vendorMemberName = vendorMemberName;
        this.logo = StringUtils.hasLength(vendorLogo) ? vendorLogo : "";
        this.totalAmount = totalAmount;
        this.innerStatus = innerStatus;
        this.innerStatusName = BuyerInnerStatusEnum.getNameByCode(innerStatus);
        this.outerStatus = outerStatus;
        this.outerStatusName = OrderOuterStatusEnum.getNameByCode(outerStatus);
        this.buyerCommented = Objects.isNull(buyerCommented) ? false : buyerCommented;
        this.hasPaid = hasPaid;
        this.hasDelivered = hasDelivered;
        this.contractId = NumberUtil.isNullOrZero(contractId) ? 0L : contractId;
        this.promotionStatus = NumberUtil.isNullOrZero(promotionStatus) ? 0 : promotionStatus;
        this.groupId = NumberUtil.isNullOrZero(groupId) ? 0L : groupId;
        this.canRefund = Objects.isNull(canRefund) ? false : canRefund;
        this.hasRefund = Objects.isNull(hasRefund) ? false : hasRefund;
        this.products = new ArrayList<>();
        this.quantities = BigDecimal.ZERO;
    }

    public MobileOrderQueryDTO(Long shopId, Long orderId, String orderNo, Integer orderType, Integer orderMode, Integer orderKind, Long vendorMemberId, Long vendorRoleId, String vendorMemberName, String vendorLogo, BigDecimal totalAmount, Integer innerStatus, Integer outerStatus, Boolean buyerCommented, Boolean hasPaid, Boolean hasDelivered, Integer promotionStatus) {
        this.shopId = shopId;
        this.orderId = orderId;
        this.orderNo = orderNo;
        this.orderMode = orderMode;
        this.orderType = orderType;
        this.orderKind = orderKind;
        this.vendorMemberId = vendorMemberId;
        this.vendorRoleId = vendorRoleId;
        this.vendorMemberName = vendorMemberName;
        this.logo = StringUtils.hasLength(vendorLogo) ? vendorLogo : "";
        this.totalAmount = totalAmount;
        this.innerStatus = innerStatus;
        this.innerStatusName = VendorInnerStatusEnum.getNameByCode(innerStatus);
        this.outerStatus = outerStatus;
        this.outerStatusName = OrderOuterStatusEnum.getNameByCode(outerStatus);
        this.buyerCommented = !Objects.isNull(buyerCommented) && buyerCommented;
        this.hasPaid = hasPaid;
        this.hasDelivered = hasDelivered;
        this.contractId = 0L;
        this.promotionStatus = NumberUtil.isNullOrZero(promotionStatus) ? 0 : promotionStatus;
        this.groupId = 0L;
        this.canRefund = false;
        this.hasRefund = false;
        this.products = new ArrayList<>();
        this.quantities = BigDecimal.ZERO;
    }

    public MobileOrderQueryDTO(Long shopId, Long orderId, String orderNo, Integer orderType, Integer orderMode, Integer orderKind, Long vendorMemberId, Long vendorRoleId, String vendorMemberName, String vendorLogo, BigDecimal totalAmount, Integer innerStatus, Integer outerStatus, Boolean buyerCommented, Boolean hasPaid, Boolean hasDelivered, Integer promotionStatus, Long groupId, Boolean canRefund, Boolean hasRefund) {
        this.shopId = shopId;
        this.orderId = orderId;
        this.orderNo = orderNo;
        this.orderType = orderType;
        this.orderMode = orderMode;
        this.orderKind = orderKind;
        this.vendorMemberId = vendorMemberId;
        this.vendorRoleId = vendorRoleId;
        this.vendorMemberName = vendorMemberName;
        this.logo = StringUtils.hasLength(vendorLogo) ? vendorLogo : "";
        this.totalAmount = totalAmount;
        this.innerStatus = innerStatus;
        this.innerStatusName = BuyerInnerStatusEnum.getNameByCode(innerStatus);
        this.outerStatus = outerStatus;
        this.outerStatusName = OrderOuterStatusEnum.getNameByCode(outerStatus);
        this.buyerCommented = !Objects.isNull(buyerCommented) && buyerCommented;
        this.hasPaid = hasPaid;
        this.hasDelivered = hasDelivered;
        this.contractId = 0L;
        this.promotionStatus = NumberUtil.isNullOrZero(promotionStatus) ? 0 : promotionStatus;
        this.groupId = NumberUtil.isNullOrZero(groupId) ? 0L : groupId;
        this.canRefund = !Objects.isNull(canRefund) && canRefund;
        this.hasRefund = !Objects.isNull(hasRefund) && hasRefund;
        this.products = new ArrayList<>();
        this.quantities = BigDecimal.ZERO;
    }

    public MobileOrderQueryDTO(Long shopId, Long orderId, String orderNo, Integer orderMode, Integer orderKind, Long vendorMemberId, Long vendorRoleId, String vendorMemberName, String vendorLogo, BigDecimal totalAmount, Integer innerStatus, Integer outerStatus, Boolean buyerCommented, Boolean hasPaid, Boolean hasDelivered, Long contractId, Integer promotionStatus, Long groupId, Boolean canRefund, Boolean hasRefund, Integer orderType) {
        this.shopId = shopId;
        this.orderId = orderId;
        this.orderNo = orderNo;
        this.orderMode = orderMode;
        this.orderKind = orderKind;
        this.vendorMemberId = vendorMemberId;
        this.vendorRoleId = vendorRoleId;
        this.vendorMemberName = vendorMemberName;
        this.logo = StringUtils.hasLength(vendorLogo) ? vendorLogo : "";
        this.totalAmount = totalAmount;
        this.innerStatus = innerStatus;
        this.innerStatusName = BuyerInnerStatusEnum.getNameByCode(innerStatus);
        this.outerStatus = outerStatus;
        this.outerStatusName = OrderOuterStatusEnum.getNameByCode(outerStatus);
        this.buyerCommented = !Objects.isNull(buyerCommented) && buyerCommented;
        this.hasPaid = hasPaid;
        this.hasDelivered = hasDelivered;
        this.contractId = NumberUtil.isNullOrZero(contractId) ? 0L : contractId;
        this.promotionStatus = NumberUtil.isNullOrZero(promotionStatus) ? 0 : promotionStatus;
        this.groupId = NumberUtil.isNullOrZero(groupId) ? 0L : groupId;
        this.canRefund = !Objects.isNull(canRefund) && canRefund;
        this.hasRefund = !Objects.isNull(hasRefund) && hasRefund;
        this.products = new ArrayList<>();
        this.quantities = BigDecimal.ZERO;
        this.orderType = orderType;
    }

//    public MobileOrderQueryDTO(Long shopId, Long orderId, String orderNo, Integer orderMode, Integer orderKind, Long vendorMemberId, Long vendorRoleId, String vendorMemberName, String vendorLogo, BigDecimal totalAmount, Integer innerStatus, Integer outerStatus, Boolean buyerCommented, Boolean hasPaid, Boolean hasDelivered, Long contractId, Integer promotionStatus, Long groupId, Boolean canRefund, Boolean hasRefund, List<MobileOrderProductQueryDTO> products) {
//        this.shopId = shopId;
//        this.orderId = orderId;
//        this.orderNo = orderNo;
//        this.orderMode = orderMode;
//        this.orderKind = orderKind;
//        this.vendorMemberId = vendorMemberId;
//        this.vendorRoleId = vendorRoleId;
//        this.vendorMemberName = vendorMemberName;
//        this.logo = StringUtils.hasLength(vendorLogo) ? vendorLogo : "";
//        this.totalAmount = totalAmount;
//        this.innerStatus = innerStatus;
//        this.innerStatusName = BuyerInnerStatusEnum.getNameByCode(innerStatus);
//        this.outerStatus = outerStatus;
//        this.outerStatusName = OrderOuterStatusEnum.getNameByCode(outerStatus);
//        this.buyerCommented = Objects.isNull(buyerCommented) ? false : buyerCommented;
//        this.hasPaid = hasPaid;
//        this.hasDelivered = hasDelivered;
//        this.contractId = NumberUtil.isNullOrZero(contractId) ? 0L : contractId;
//        this.promotionStatus = NumberUtil.isNullOrZero(promotionStatus) ? 0 : promotionStatus;
//        this.groupId = NumberUtil.isNullOrZero(groupId) ? 0L : groupId;
//        this.canRefund = Objects.isNull(canRefund) ? false : canRefund;
//        this.hasRefund = Objects.isNull(hasRefund) ? false : hasRefund;
//        this.products = products;
//        this.quantities = CollectionUtils.isEmpty(products) ? BigDecimal.ZERO : products.stream().map(MobileOrderProductQueryDTO::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);
//    }

    /**
     * 订单来源商城Id
     */
    private Long shopId;

    /**
     * 订单Id
     */
    private Long orderId;

    /**
     * 订单编号
     */
    private String orderNo;

    /**
     * 下单模式
     */
    private Integer orderMode;

    /**
     * 下单来源
     */
    private Integer orderKind;

    /**
     * 供应会员Id
     */
    private Long vendorMemberId;

    /**
     * 供应会员角色Id
     */
    private Long vendorRoleId;

    /**
     * 供应会员名称
     */
    private String vendorMemberName;

    /**
     * 供应会员店铺logo
     */
    private String logo;

    /**
     * 订单总金额
     */
    private BigDecimal totalAmount;

    /**
     * 订单商品总数量
     */
    private BigDecimal quantities;

    /**
     * 内部状态枚举
     */
    private Integer innerStatus;

    /**
     * 内部状态名称
     */
    private String innerStatusName;

    /**
     * 外部状态枚举
     */
    private Integer outerStatus;

    /**
     * 外部状态名称
     */
    private String outerStatusName;

    /**
     * 采购商是否评论过订单
     */
    private Boolean buyerCommented;

    /**
     * 是否支付过
     */
    private Boolean hasPaid;

    /**
     * 是否发过货
     */
    private Boolean hasDelivered;

    /**
     * 合同Id
     */
    private Long contractId;

    /**
     * 营销活动状态
     */
    private Integer promotionStatus;

    /**
     * 拼团Id
     */
    private Long groupId;

    /**
     * 是否满足退款条件
     */
    private Boolean canRefund;

    /**
     * 是否已经完全退款
     */
    private Boolean hasRefund;

    /**
     * 订单类型
     */
    private Integer orderType;

    /**
     * 商品列表
     */
    private List<MobileOrderProductQueryDTO> products;

    public Long getShopId() {
        return shopId;
    }

    public void setShopId(Long shopId) {
        this.shopId = shopId;
    }

    public Long getOrderId() {
        return orderId;
    }

    public void setOrderId(Long orderId) {
        this.orderId = orderId;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public Integer getOrderMode() {
        return orderMode;
    }

    public void setOrderMode(Integer orderMode) {
        this.orderMode = orderMode;
    }

    public Integer getOrderKind() {
        return orderKind;
    }

    public void setOrderKind(Integer orderKind) {
        this.orderKind = orderKind;
    }

    public Long getVendorMemberId() {
        return vendorMemberId;
    }

    public void setVendorMemberId(Long vendorMemberId) {
        this.vendorMemberId = vendorMemberId;
    }

    public Long getVendorRoleId() {
        return vendorRoleId;
    }

    public void setVendorRoleId(Long vendorRoleId) {
        this.vendorRoleId = vendorRoleId;
    }

    public String getVendorMemberName() {
        return vendorMemberName;
    }

    public void setVendorMemberName(String vendorMemberName) {
        this.vendorMemberName = vendorMemberName;
    }

    public String getLogo() {
        return logo;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    public BigDecimal getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public BigDecimal getQuantities() {
        return quantities;
    }

    public void setQuantities(BigDecimal quantities) {
        this.quantities = quantities;
    }

    public Integer getInnerStatus() {
        return innerStatus;
    }

    public void setInnerStatus(Integer innerStatus) {
        this.innerStatus = innerStatus;
    }

    public String getInnerStatusName() {
        return innerStatusName;
    }

    public void setInnerStatusName(String innerStatusName) {
        this.innerStatusName = innerStatusName;
    }

    public Integer getOuterStatus() {
        return outerStatus;
    }

    public void setOuterStatus(Integer outerStatus) {
        this.outerStatus = outerStatus;
    }

    public String getOuterStatusName() {
        return outerStatusName;
    }

    public void setOuterStatusName(String outerStatusName) {
        this.outerStatusName = outerStatusName;
    }

    public Boolean getBuyerCommented() {
        return buyerCommented;
    }

    public void setBuyerCommented(Boolean buyerCommented) {
        this.buyerCommented = buyerCommented;
    }

    public Boolean getHasPaid() {
        return hasPaid;
    }

    public void setHasPaid(Boolean hasPaid) {
        this.hasPaid = hasPaid;
    }

    public Boolean getHasDelivered() {
        return hasDelivered;
    }

    public void setHasDelivered(Boolean hasDelivered) {
        this.hasDelivered = hasDelivered;
    }

    public Long getContractId() {
        return contractId;
    }

    public void setContractId(Long contractId) {
        this.contractId = contractId;
    }

    public Integer getPromotionStatus() {
        return promotionStatus;
    }

    public void setPromotionStatus(Integer promotionStatus) {
        this.promotionStatus = promotionStatus;
    }

    public Long getGroupId() {
        return groupId;
    }

    public void setGroupId(Long groupId) {
        this.groupId = groupId;
    }

    public Boolean getCanRefund() {
        return canRefund;
    }

    public void setCanRefund(Boolean canRefund) {
        this.canRefund = canRefund;
    }

    public Boolean getHasRefund() {
        return hasRefund;
    }

    public void setHasRefund(Boolean hasRefund) {
        this.hasRefund = hasRefund;
    }

    public List<MobileOrderProductQueryDTO> getProducts() {
        return products;
    }

    public void setProducts(List<MobileOrderProductQueryDTO> products) {
        this.products = products;
        this.quantities = CollectionUtils.isEmpty(products) ? BigDecimal.ZERO : products.stream().map(MobileOrderProductQueryDTO::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);
    }

    public Integer getOrderType() {
        return orderType;
    }

    public void setOrderType(Integer orderType) {
        this.orderType = orderType;
    }
}
